// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"log"
	"reflect"

	"server/components/models/ent/migrate"

	"server/components/models/ent/forecast"
	"server/components/models/ent/region"
	"server/components/models/ent/regiontype"
	"server/components/models/ent/user"
	"server/components/models/ent/weather"

	"entgo.io/ent"
	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
)

// Client is the client that holds all ent builders.
type Client struct {
	config
	// Schema is the client for creating, migrating and dropping schema.
	Schema *migrate.Schema
	// Forecast is the client for interacting with the Forecast builders.
	Forecast *ForecastClient
	// Region is the client for interacting with the Region builders.
	Region *RegionClient
	// RegionType is the client for interacting with the RegionType builders.
	RegionType *RegionTypeClient
	// User is the client for interacting with the User builders.
	User *UserClient
	// Weather is the client for interacting with the Weather builders.
	Weather *WeatherClient
}

// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
	client := &Client{config: newConfig(opts...)}
	client.init()
	return client
}

func (c *Client) init() {
	c.Schema = migrate.NewSchema(c.driver)
	c.Forecast = NewForecastClient(c.config)
	c.Region = NewRegionClient(c.config)
	c.RegionType = NewRegionTypeClient(c.config)
	c.User = NewUserClient(c.config)
	c.Weather = NewWeatherClient(c.config)
}

type (
	// config is the configuration for the client and its builder.
	config struct {
		// driver used for executing database requests.
		driver dialect.Driver
		// debug enable a debug logging.
		debug bool
		// log used for logging on debug mode.
		log func(...any)
		// hooks to execute on mutations.
		hooks *hooks
		// interceptors to execute on queries.
		inters *inters
	}
	// Option function to configure the client.
	Option func(*config)
)

// newConfig creates a new config for the client.
func newConfig(opts ...Option) config {
	cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
	cfg.options(opts...)
	return cfg
}

// options applies the options on the config object.
func (c *config) options(opts ...Option) {
	for _, opt := range opts {
		opt(c)
	}
	if c.debug {
		c.driver = dialect.Debug(c.driver, c.log)
	}
}

// Debug enables debug logging on the ent.Driver.
func Debug() Option {
	return func(c *config) {
		c.debug = true
	}
}

// Log sets the logging function for debug mode.
func Log(fn func(...any)) Option {
	return func(c *config) {
		c.log = fn
	}
}

// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
	return func(c *config) {
		c.driver = driver
	}
}

// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
	switch driverName {
	case dialect.MySQL, dialect.Postgres, dialect.SQLite:
		drv, err := sql.Open(driverName, dataSourceName)
		if err != nil {
			return nil, err
		}
		return NewClient(append(options, Driver(drv))...), nil
	default:
		return nil, fmt.Errorf("unsupported driver: %q", driverName)
	}
}

// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")

// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
	if _, ok := c.driver.(*txDriver); ok {
		return nil, ErrTxStarted
	}
	tx, err := newTx(ctx, c.driver)
	if err != nil {
		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = tx
	return &Tx{
		ctx:        ctx,
		config:     cfg,
		Forecast:   NewForecastClient(cfg),
		Region:     NewRegionClient(cfg),
		RegionType: NewRegionTypeClient(cfg),
		User:       NewUserClient(cfg),
		Weather:    NewWeatherClient(cfg),
	}, nil
}

// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
	if _, ok := c.driver.(*txDriver); ok {
		return nil, errors.New("ent: cannot start a transaction within a transaction")
	}
	tx, err := c.driver.(interface {
		BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
	}).BeginTx(ctx, opts)
	if err != nil {
		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = &txDriver{tx: tx, drv: c.driver}
	return &Tx{
		ctx:        ctx,
		config:     cfg,
		Forecast:   NewForecastClient(cfg),
		Region:     NewRegionClient(cfg),
		RegionType: NewRegionTypeClient(cfg),
		User:       NewUserClient(cfg),
		Weather:    NewWeatherClient(cfg),
	}, nil
}

// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
//	client.Debug().
//		Forecast.
//		Query().
//		Count(ctx)
func (c *Client) Debug() *Client {
	if c.debug {
		return c
	}
	cfg := c.config
	cfg.driver = dialect.Debug(c.driver, c.log)
	client := &Client{config: cfg}
	client.init()
	return client
}

// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
	return c.driver.Close()
}

// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
	c.Forecast.Use(hooks...)
	c.Region.Use(hooks...)
	c.RegionType.Use(hooks...)
	c.User.Use(hooks...)
	c.Weather.Use(hooks...)
}

// Intercept adds the query interceptors to all the entity clients.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
	c.Forecast.Intercept(interceptors...)
	c.Region.Intercept(interceptors...)
	c.RegionType.Intercept(interceptors...)
	c.User.Intercept(interceptors...)
	c.Weather.Intercept(interceptors...)
}

// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
	switch m := m.(type) {
	case *ForecastMutation:
		return c.Forecast.mutate(ctx, m)
	case *RegionMutation:
		return c.Region.mutate(ctx, m)
	case *RegionTypeMutation:
		return c.RegionType.mutate(ctx, m)
	case *UserMutation:
		return c.User.mutate(ctx, m)
	case *WeatherMutation:
		return c.Weather.mutate(ctx, m)
	default:
		return nil, fmt.Errorf("ent: unknown mutation type %T", m)
	}
}

// ForecastClient is a client for the Forecast schema.
type ForecastClient struct {
	config
}

// NewForecastClient returns a client for the Forecast from the given config.
func NewForecastClient(c config) *ForecastClient {
	return &ForecastClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `forecast.Hooks(f(g(h())))`.
func (c *ForecastClient) Use(hooks ...Hook) {
	c.hooks.Forecast = append(c.hooks.Forecast, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `forecast.Intercept(f(g(h())))`.
func (c *ForecastClient) Intercept(interceptors ...Interceptor) {
	c.inters.Forecast = append(c.inters.Forecast, interceptors...)
}

// Create returns a builder for creating a Forecast entity.
func (c *ForecastClient) Create() *ForecastCreate {
	mutation := newForecastMutation(c.config, OpCreate)
	return &ForecastCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of Forecast entities.
func (c *ForecastClient) CreateBulk(builders ...*ForecastCreate) *ForecastCreateBulk {
	return &ForecastCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ForecastClient) MapCreateBulk(slice any, setFunc func(*ForecastCreate, int)) *ForecastCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &ForecastCreateBulk{err: fmt.Errorf("calling to ForecastClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*ForecastCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &ForecastCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for Forecast.
func (c *ForecastClient) Update() *ForecastUpdate {
	mutation := newForecastMutation(c.config, OpUpdate)
	return &ForecastUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *ForecastClient) UpdateOne(f *Forecast) *ForecastUpdateOne {
	mutation := newForecastMutation(c.config, OpUpdateOne, withForecast(f))
	return &ForecastUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *ForecastClient) UpdateOneID(id int64) *ForecastUpdateOne {
	mutation := newForecastMutation(c.config, OpUpdateOne, withForecastID(id))
	return &ForecastUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for Forecast.
func (c *ForecastClient) Delete() *ForecastDelete {
	mutation := newForecastMutation(c.config, OpDelete)
	return &ForecastDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *ForecastClient) DeleteOne(f *Forecast) *ForecastDeleteOne {
	return c.DeleteOneID(f.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ForecastClient) DeleteOneID(id int64) *ForecastDeleteOne {
	builder := c.Delete().Where(forecast.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &ForecastDeleteOne{builder}
}

// Query returns a query builder for Forecast.
func (c *ForecastClient) Query() *ForecastQuery {
	return &ForecastQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeForecast},
		inters: c.Interceptors(),
	}
}

// Get returns a Forecast entity by its id.
func (c *ForecastClient) Get(ctx context.Context, id int64) (*Forecast, error) {
	return c.Query().Where(forecast.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *ForecastClient) GetX(ctx context.Context, id int64) *Forecast {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryRegion queries the region edge of a Forecast.
func (c *ForecastClient) QueryRegion(f *Forecast) *RegionQuery {
	query := (&RegionClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := f.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(forecast.Table, forecast.FieldID, id),
			sqlgraph.To(region.Table, region.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, forecast.RegionTable, forecast.RegionColumn),
		)
		fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryRegionWeather queries the regionWeather edge of a Forecast.
func (c *ForecastClient) QueryRegionWeather(f *Forecast) *WeatherQuery {
	query := (&WeatherClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := f.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(forecast.Table, forecast.FieldID, id),
			sqlgraph.To(weather.Table, weather.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, true, forecast.RegionWeatherTable, forecast.RegionWeatherColumn),
		)
		fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *ForecastClient) Hooks() []Hook {
	return c.hooks.Forecast
}

// Interceptors returns the client interceptors.
func (c *ForecastClient) Interceptors() []Interceptor {
	return c.inters.Forecast
}

func (c *ForecastClient) mutate(ctx context.Context, m *ForecastMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&ForecastCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&ForecastUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&ForecastUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&ForecastDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown Forecast mutation op: %q", m.Op())
	}
}

// RegionClient is a client for the Region schema.
type RegionClient struct {
	config
}

// NewRegionClient returns a client for the Region from the given config.
func NewRegionClient(c config) *RegionClient {
	return &RegionClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `region.Hooks(f(g(h())))`.
func (c *RegionClient) Use(hooks ...Hook) {
	c.hooks.Region = append(c.hooks.Region, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `region.Intercept(f(g(h())))`.
func (c *RegionClient) Intercept(interceptors ...Interceptor) {
	c.inters.Region = append(c.inters.Region, interceptors...)
}

// Create returns a builder for creating a Region entity.
func (c *RegionClient) Create() *RegionCreate {
	mutation := newRegionMutation(c.config, OpCreate)
	return &RegionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of Region entities.
func (c *RegionClient) CreateBulk(builders ...*RegionCreate) *RegionCreateBulk {
	return &RegionCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *RegionClient) MapCreateBulk(slice any, setFunc func(*RegionCreate, int)) *RegionCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &RegionCreateBulk{err: fmt.Errorf("calling to RegionClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*RegionCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &RegionCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for Region.
func (c *RegionClient) Update() *RegionUpdate {
	mutation := newRegionMutation(c.config, OpUpdate)
	return &RegionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *RegionClient) UpdateOne(r *Region) *RegionUpdateOne {
	mutation := newRegionMutation(c.config, OpUpdateOne, withRegion(r))
	return &RegionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *RegionClient) UpdateOneID(id int64) *RegionUpdateOne {
	mutation := newRegionMutation(c.config, OpUpdateOne, withRegionID(id))
	return &RegionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for Region.
func (c *RegionClient) Delete() *RegionDelete {
	mutation := newRegionMutation(c.config, OpDelete)
	return &RegionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *RegionClient) DeleteOne(r *Region) *RegionDeleteOne {
	return c.DeleteOneID(r.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *RegionClient) DeleteOneID(id int64) *RegionDeleteOne {
	builder := c.Delete().Where(region.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &RegionDeleteOne{builder}
}

// Query returns a query builder for Region.
func (c *RegionClient) Query() *RegionQuery {
	return &RegionQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeRegion},
		inters: c.Interceptors(),
	}
}

// Get returns a Region entity by its id.
func (c *RegionClient) Get(ctx context.Context, id int64) (*Region, error) {
	return c.Query().Where(region.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *RegionClient) GetX(ctx context.Context, id int64) *Region {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryRegionType queries the regionType edge of a Region.
func (c *RegionClient) QueryRegionType(r *Region) *RegionTypeQuery {
	query := (&RegionTypeClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := r.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(region.Table, region.FieldID, id),
			sqlgraph.To(regiontype.Table, regiontype.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, region.RegionTypeTable, region.RegionTypeColumn),
		)
		fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryAccountId queries the accountId edge of a Region.
func (c *RegionClient) QueryAccountId(r *Region) *UserQuery {
	query := (&UserClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := r.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(region.Table, region.FieldID, id),
			sqlgraph.To(user.Table, user.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, region.AccountIdTable, region.AccountIdColumn),
		)
		fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *RegionClient) Hooks() []Hook {
	return c.hooks.Region
}

// Interceptors returns the client interceptors.
func (c *RegionClient) Interceptors() []Interceptor {
	return c.inters.Region
}

func (c *RegionClient) mutate(ctx context.Context, m *RegionMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&RegionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&RegionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&RegionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&RegionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown Region mutation op: %q", m.Op())
	}
}

// RegionTypeClient is a client for the RegionType schema.
type RegionTypeClient struct {
	config
}

// NewRegionTypeClient returns a client for the RegionType from the given config.
func NewRegionTypeClient(c config) *RegionTypeClient {
	return &RegionTypeClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `regiontype.Hooks(f(g(h())))`.
func (c *RegionTypeClient) Use(hooks ...Hook) {
	c.hooks.RegionType = append(c.hooks.RegionType, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `regiontype.Intercept(f(g(h())))`.
func (c *RegionTypeClient) Intercept(interceptors ...Interceptor) {
	c.inters.RegionType = append(c.inters.RegionType, interceptors...)
}

// Create returns a builder for creating a RegionType entity.
func (c *RegionTypeClient) Create() *RegionTypeCreate {
	mutation := newRegionTypeMutation(c.config, OpCreate)
	return &RegionTypeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of RegionType entities.
func (c *RegionTypeClient) CreateBulk(builders ...*RegionTypeCreate) *RegionTypeCreateBulk {
	return &RegionTypeCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *RegionTypeClient) MapCreateBulk(slice any, setFunc func(*RegionTypeCreate, int)) *RegionTypeCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &RegionTypeCreateBulk{err: fmt.Errorf("calling to RegionTypeClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*RegionTypeCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &RegionTypeCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for RegionType.
func (c *RegionTypeClient) Update() *RegionTypeUpdate {
	mutation := newRegionTypeMutation(c.config, OpUpdate)
	return &RegionTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *RegionTypeClient) UpdateOne(rt *RegionType) *RegionTypeUpdateOne {
	mutation := newRegionTypeMutation(c.config, OpUpdateOne, withRegionType(rt))
	return &RegionTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *RegionTypeClient) UpdateOneID(id int64) *RegionTypeUpdateOne {
	mutation := newRegionTypeMutation(c.config, OpUpdateOne, withRegionTypeID(id))
	return &RegionTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for RegionType.
func (c *RegionTypeClient) Delete() *RegionTypeDelete {
	mutation := newRegionTypeMutation(c.config, OpDelete)
	return &RegionTypeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *RegionTypeClient) DeleteOne(rt *RegionType) *RegionTypeDeleteOne {
	return c.DeleteOneID(rt.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *RegionTypeClient) DeleteOneID(id int64) *RegionTypeDeleteOne {
	builder := c.Delete().Where(regiontype.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &RegionTypeDeleteOne{builder}
}

// Query returns a query builder for RegionType.
func (c *RegionTypeClient) Query() *RegionTypeQuery {
	return &RegionTypeQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeRegionType},
		inters: c.Interceptors(),
	}
}

// Get returns a RegionType entity by its id.
func (c *RegionTypeClient) Get(ctx context.Context, id int64) (*RegionType, error) {
	return c.Query().Where(regiontype.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *RegionTypeClient) GetX(ctx context.Context, id int64) *RegionType {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// Hooks returns the client hooks.
func (c *RegionTypeClient) Hooks() []Hook {
	return c.hooks.RegionType
}

// Interceptors returns the client interceptors.
func (c *RegionTypeClient) Interceptors() []Interceptor {
	return c.inters.RegionType
}

func (c *RegionTypeClient) mutate(ctx context.Context, m *RegionTypeMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&RegionTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&RegionTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&RegionTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&RegionTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown RegionType mutation op: %q", m.Op())
	}
}

// UserClient is a client for the User schema.
type UserClient struct {
	config
}

// NewUserClient returns a client for the User from the given config.
func NewUserClient(c config) *UserClient {
	return &UserClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
func (c *UserClient) Use(hooks ...Hook) {
	c.hooks.User = append(c.hooks.User, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
func (c *UserClient) Intercept(interceptors ...Interceptor) {
	c.inters.User = append(c.inters.User, interceptors...)
}

// Create returns a builder for creating a User entity.
func (c *UserClient) Create() *UserCreate {
	mutation := newUserMutation(c.config, OpCreate)
	return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of User entities.
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
	return &UserCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*UserCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &UserCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for User.
func (c *UserClient) Update() *UserUpdate {
	mutation := newUserMutation(c.config, OpUpdate)
	return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *UserClient) UpdateOne(u *User) *UserUpdateOne {
	mutation := newUserMutation(c.config, OpUpdateOne, withUser(u))
	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *UserClient) UpdateOneID(id int) *UserUpdateOne {
	mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for User.
func (c *UserClient) Delete() *UserDelete {
	mutation := newUserMutation(c.config, OpDelete)
	return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *UserClient) DeleteOne(u *User) *UserDeleteOne {
	return c.DeleteOneID(u.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
	builder := c.Delete().Where(user.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &UserDeleteOne{builder}
}

// Query returns a query builder for User.
func (c *UserClient) Query() *UserQuery {
	return &UserQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeUser},
		inters: c.Interceptors(),
	}
}

// Get returns a User entity by its id.
func (c *UserClient) Get(ctx context.Context, id int) (*User, error) {
	return c.Query().Where(user.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *UserClient) GetX(ctx context.Context, id int) *User {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// Hooks returns the client hooks.
func (c *UserClient) Hooks() []Hook {
	return c.hooks.User
}

// Interceptors returns the client interceptors.
func (c *UserClient) Interceptors() []Interceptor {
	return c.inters.User
}

func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
	}
}

// WeatherClient is a client for the Weather schema.
type WeatherClient struct {
	config
}

// NewWeatherClient returns a client for the Weather from the given config.
func NewWeatherClient(c config) *WeatherClient {
	return &WeatherClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `weather.Hooks(f(g(h())))`.
func (c *WeatherClient) Use(hooks ...Hook) {
	c.hooks.Weather = append(c.hooks.Weather, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `weather.Intercept(f(g(h())))`.
func (c *WeatherClient) Intercept(interceptors ...Interceptor) {
	c.inters.Weather = append(c.inters.Weather, interceptors...)
}

// Create returns a builder for creating a Weather entity.
func (c *WeatherClient) Create() *WeatherCreate {
	mutation := newWeatherMutation(c.config, OpCreate)
	return &WeatherCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of Weather entities.
func (c *WeatherClient) CreateBulk(builders ...*WeatherCreate) *WeatherCreateBulk {
	return &WeatherCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *WeatherClient) MapCreateBulk(slice any, setFunc func(*WeatherCreate, int)) *WeatherCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &WeatherCreateBulk{err: fmt.Errorf("calling to WeatherClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*WeatherCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &WeatherCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for Weather.
func (c *WeatherClient) Update() *WeatherUpdate {
	mutation := newWeatherMutation(c.config, OpUpdate)
	return &WeatherUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *WeatherClient) UpdateOne(w *Weather) *WeatherUpdateOne {
	mutation := newWeatherMutation(c.config, OpUpdateOne, withWeather(w))
	return &WeatherUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *WeatherClient) UpdateOneID(id int64) *WeatherUpdateOne {
	mutation := newWeatherMutation(c.config, OpUpdateOne, withWeatherID(id))
	return &WeatherUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for Weather.
func (c *WeatherClient) Delete() *WeatherDelete {
	mutation := newWeatherMutation(c.config, OpDelete)
	return &WeatherDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *WeatherClient) DeleteOne(w *Weather) *WeatherDeleteOne {
	return c.DeleteOneID(w.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *WeatherClient) DeleteOneID(id int64) *WeatherDeleteOne {
	builder := c.Delete().Where(weather.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &WeatherDeleteOne{builder}
}

// Query returns a query builder for Weather.
func (c *WeatherClient) Query() *WeatherQuery {
	return &WeatherQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeWeather},
		inters: c.Interceptors(),
	}
}

// Get returns a Weather entity by its id.
func (c *WeatherClient) Get(ctx context.Context, id int64) (*Weather, error) {
	return c.Query().Where(weather.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *WeatherClient) GetX(ctx context.Context, id int64) *Weather {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryRegion queries the region edge of a Weather.
func (c *WeatherClient) QueryRegion(w *Weather) *RegionQuery {
	query := (&RegionClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := w.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(weather.Table, weather.FieldID, id),
			sqlgraph.To(region.Table, region.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, weather.RegionTable, weather.RegionColumn),
		)
		fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryForecast queries the forecast edge of a Weather.
func (c *WeatherClient) QueryForecast(w *Weather) *ForecastQuery {
	query := (&ForecastClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := w.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(weather.Table, weather.FieldID, id),
			sqlgraph.To(forecast.Table, forecast.FieldID),
			sqlgraph.Edge(sqlgraph.O2M, false, weather.ForecastTable, weather.ForecastColumn),
		)
		fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *WeatherClient) Hooks() []Hook {
	return c.hooks.Weather
}

// Interceptors returns the client interceptors.
func (c *WeatherClient) Interceptors() []Interceptor {
	return c.inters.Weather
}

func (c *WeatherClient) mutate(ctx context.Context, m *WeatherMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&WeatherCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&WeatherUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&WeatherUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&WeatherDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown Weather mutation op: %q", m.Op())
	}
}

// hooks and interceptors per client, for fast access.
type (
	hooks struct {
		Forecast, Region, RegionType, User, Weather []ent.Hook
	}
	inters struct {
		Forecast, Region, RegionType, User, Weather []ent.Interceptor
	}
)
